//
//  ViewController.m
//  MKLab
//
//  Created by 苏尚进 on 2021/7/29.
//

#import "MKLViewController.h"
#import <MKUI/MKUI.h>
#import "MKLLoadObjectTest.h"
#import "MKLGlobalConfig.h"
@interface MKLViewController ()
@property(nonatomic,strong) UILabel *textLabel;

@end

@implementation MKLViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.textLabel = [[UILabel alloc] init];
    self.textLabel.numberOfLines = 0;
    self.textLabel.textAlignment = NSTextAlignmentCenter;
    self.textLabel.font = [UIFont boldSystemFontOfSize:24];
    self.textLabel.textColor = [UIColor blackColor];
    
    NSBundle *bundleInMain = [NSBundle bundleWithPath:[[NSBundle mainBundle] pathForResource:@"MKLabBundle" ofType:@"bundle"]];//bundle直接打包到ipa中
    NSBundle *bundleInDyFramework = [NSBundle bundleWithPath:[[NSBundle mainBundle] pathForResource:@"Frameworks/MKLabDynamicFramework.framework/MKLabBundle" ofType:@"bundle"]];//bundle打包到动态库MKLabDynamicFramework.framework，由于动态库要求embed到ipa中，因此在ipa中其路径为Frameworks/MKLabDynamicFramework.framework/MKLabBundle.bundle
    NSBundle *bundleInStFramework = [NSBundle bundleWithPath:[[NSBundle mainBundle] pathForResource:@"Frameworks/MKLabStaticFramework.framework/MKLabBundle" ofType:@"bundle"]];//bundle打包到静态库MKLabStaticFramework.framework，由于静态库非强制embed。因此如果静态库framework没有embed到ipa，则bundle不会被打包到ipa中，无法进行访问
    NSLog(@"bundleInStFramework:%@",bundleInStFramework);
    NSString *text1 = [NSString stringWithContentsOfFile:[bundleInMain pathForResource:@"text.txt" ofType:nil] encoding:NSUTF8StringEncoding error:nil];
    NSString *text2 = [NSString stringWithContentsOfFile:[bundleInDyFramework pathForResource:@"json.txt" ofType:nil] encoding:NSUTF8StringEncoding error:nil];
    self.textLabel.text = [NSString stringWithFormat:@"%@\n%@\n%@\n%@",text1,text2,[MKLGlobalConfig sharedInstance].appID,[MKLGlobalConfig appID]];
    [self.view addSubview:self.textLabel];
    [MKUIFlowLayoutButton new];
    [MKLLoadObjectTest new];
}

- (void)viewWillLayoutSubviews{
    [super viewWillLayoutSubviews];
    CGRect bounds = self.view.bounds;
    UIEdgeInsets insets = UIEdgeInsetsZero;
    if (@available(iOS 11.0, *)) {
        insets = self.view.safeAreaInsets;
    }
    CGRect f1 = UIEdgeInsetsInsetRect(bounds, insets);
    self.textLabel.frame = f1;
}

@end
